//
// FannTool, GUI tool for ANN by using FANN library
// Programmed by BlueKid
// http://derindelimavi.blogspot.com/
// Send me any suggestion, modification or bugs. 
// Don't hesitate to contact  me for any question, 
// I will be very grateful with your feedbacks.
// bluekid70@gmail.com
// Copyright (C) 2008  BlueKid
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or  any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//

// generated by Fast Light User Interface Designer (fluid) version 1.0110

#ifndef main_h
#define main_h
#include <FL/Fl.H>
#include <string>
#include <math.h>
#include <deque>
#include "Fl_PlotXY.H"
#include "DataProcess.h"
#include "FileSelect.h"
#include <FL/fl_ask.H>
#include <FL/Fl_Float_Input.H>
#include <FL/Fl_File_Chooser.H>
#include <FL/Fl_Chart.H>
#include <FL/filename.H>
#include <stdio.h>
#include <fann.h>
#include <FL/Fl_Double_Window.H>
extern Fl_Double_Window *window_main;
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Input.H>
extern Fl_Input *DataFile;
extern Fl_Input *TestFile;
#include <FL/Fl_Repeat_Button.H>
#include <FL/Fl_Value_Output.H>
extern Fl_Value_Output *Input;
extern Fl_Value_Output *Output;
#include <FL/Fl_Spinner.H>
extern Fl_Spinner *Layer;
extern Fl_Spinner *Hid1;
extern Fl_Spinner *Hid2;
extern Fl_Spinner *Hid3;
#include <FL/Fl_Choice.H>
extern Fl_Choice *Method;
extern Fl_Choice *HiddenActivationF;
extern Fl_Choice *OutputActivationF;
extern Fl_Choice *StopFunction;
#include <FL/Fl_Value_Input.H>
extern Fl_Value_Input *EReports;
extern Fl_Value_Input *MaxEpoch;
#include <FL/Fl_Tabs.H>
extern Fl_Tabs *Tabs;
extern Fl_Group *LogG;
#include <FL/Fl_Browser.H>
extern Fl_Browser *Out;
extern Fl_Group *GraphG;
extern Fl_PlotXY *Graph;
extern Fl_Value_Output *Ep;
extern Fl_Value_Output *Mse;
extern Fl_Spinner *nVData;
extern Fl_Value_Output *BitFailOut;
extern Fl_Value_Output *TestMse;
extern Fl_Value_Input *DesiredError;
extern Fl_Value_Input *BitFail;
extern Fl_Choice *ErrorFunction;
extern Fl_Value_Input *HiddenStepness;
extern Fl_Value_Input *OutputStepness;
extern Fl_Value_Input *DecayFactor;
extern Fl_Value_Input *MuFactor;
extern Fl_Value_Input *IncreaseFactor;
extern Fl_Value_Input *DecreaseFactor;
extern Fl_Value_Input *DeltaMin;
extern Fl_Value_Input *DeltaMax;
#include <FL/Fl_Counter.H>
extern Fl_Counter *ConnectionRate;
extern Fl_Counter *Momentum;
#include <FL/Fl_Check_Button.H>
extern Fl_Check_Button *Shuffle;
extern Fl_Check_Button *InitWghts;
extern Fl_Check_Button *OverTraining;
extern Fl_Spinner *LearningRate;
extern Fl_Value_Input *OutputChange;
extern Fl_Value_Input *OutputStag;
extern Fl_Value_Input *CandidateChange;
extern Fl_Value_Input *CandidateStag;
extern Fl_Value_Input *WeighMultiplier;
extern Fl_Value_Input *CandidateLimit;
extern Fl_Value_Input *MaxOutEpoch;
extern Fl_Value_Input *MaxCasndidatetEpoch;
extern Fl_Value_Input *NumCandidateGroups;
extern Fl_Value_Input *MaxCascade;
#include <FL/Fl_Button.H>
extern Fl_Button *But_Alg;
extern Fl_Button *But_Act;
#include <FL/Fl_Menu_Button.H>
extern Fl_Menu_Button *But_Trn;
extern Fl_Button *But_Test;
extern Fl_Menu_Button *But_Run;
extern Fl_Button *Stop;
extern Fl_Menu_Item menu_[];
void cb_Ok(Fl_Return_Button*o, void*w);
inline void Refresh();
void FillMethods();
void FillActivationF();
struct fann* fann_copy(const struct fann* orig);
fann_type * GetWeigths(struct fann *ann);
void SetWeights(struct fann *ann,fann_type *w);
fann_type ExamineTrain(struct fann *ann,fann_train_enum tal,fann_activationfunc_enum hact,fann_activationfunc_enum oact,fann_train_data *TrainData);
int FANN_API LogOut(struct fann *ann, struct fann_train_data *train,unsigned int max_epochs, unsigned int epochs_between_reports,float desired_error, unsigned int epochs);
int FANN_API CascadeLogOut(struct fann *ann, struct fann_train_data *train,unsigned int max_epochs, unsigned int epochs_between_reports,float desired_error, unsigned int epochs);
int FANN_API DrawGraph(float epochs, float TrainMSE, float TestMSE,unsigned int newBitFail);
void SetHiddens();
void InactImg(Fl_Widget* o);

class FannTool {
public:
  struct fann *ysa;
  fann_type *result; 
  fann_type *data; 
  bool working; 
  bool stop; 
  bool overtraining; 
  fann_train_data *TrainData; 
  fann_train_data *TestData; 
  FannTool();
  void OptimumAlgorithm();
  void OptimumActivations();
  void TrainNormal();
  void TrainCascade();
  void Test();
  void Run();
  void RunNormal();
  void RunwithFile();
  void RunAsTS();
  void ClearLog();
  void SaveLog();
  void LoadLog();
  void StopProcess();
  void About();
  void Help();
  void DataProcessing();
  void LoadTrainData();
  void LoadTestData();
  void SetFineTuning();
  void SetCascadeTuning();
  void NeuralNetworkInfo();
private:
  void CreateDesiredANN();
  void ActivateStop();
  void DeactivateStop();
  void SaveANN();
  void ClearTrainingMemory();
};
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Return_Button.H>
extern void cb_Ok(Fl_Return_Button*, void*);

class GetInputs {
public:
  struct fann *ann;
  int ninputs, noutputs; 
  bool tseries; 
private:
  fann_type *data,*result; 
public:
  GetInputs(bool ts=false);
  Fl_Double_Window *window;
  Fl_Scroll *Grid;
  Fl_Return_Button *Ok;
  Fl_Scroll *GridOut;
private:
  void cb_Run_i(Fl_Button*, void*);
  static void cb_Run(Fl_Button*, void*);
public:
  Fl_Spinner *kere;
  void show(struct fann *iann);
  void hide();
  void Run();
  void RunTS();
};
#include <FL/Fl_Box.H>
#include <FL/Fl_Output.H>

class NetInfo {
  vector<double> weights; 
public:
  struct fann *ann;
  NetInfo();
  Fl_Double_Window *window;
  Fl_Return_Button *Ok;
  Fl_Value_Output *Input;
  Fl_Browser *Hidden;
  Fl_Value_Output *Output;
  Fl_Output *NType;
  Fl_Output *Alg;
  Fl_Output *Err;
  Fl_Output *Stop;
  Fl_Choice *WLabel;
private:
  void cb_WLabel_i(Fl_Choice*, void*);
  static void cb_WLabel(Fl_Choice*, void*);
public:
  Fl_Value_Output *WValue;
  void show(struct fann *iann);
  void hide();
};
#include <FL/Fl_Help_View.H>

class AboutDlg {
public:
  AboutDlg();
  Fl_Double_Window *window;
  Fl_Return_Button *Ok;
  Fl_Help_View *Help;
  void show();
  void hide();
};
#include <FL/Fl_Round_Button.H>

class SaveDlg {
public:
  SaveDlg();
  Fl_Double_Window *window;
  Fl_Return_Button *Ok;
  Fl_Round_Button *Latest;
  Fl_Round_Button *ANN0;
  Fl_Round_Button *ANN1;
  Fl_Round_Button *ANN2;
  Fl_Group *OCS1;
  Fl_Group *OCS2;
private:
  void cb_Save1_i(Fl_Button*, void*);
  static void cb_Save1(Fl_Button*, void*);
public:
  void show();
  void hide();
  ~SaveDlg();
};
#include <FL/Fl_Value_Slider.H>

class NDPDlg {
public:
  NDPDlg(char * FileName);
  Fl_Double_Window *window;
  Fl_Return_Button *Ok;
private:
  void cb_Ok_i(Fl_Return_Button*, void*);
  static void cb_Ok(Fl_Return_Button*, void*);
public:
  Fl_Output *RawFile;
  Fl_Value_Output *nDataPoint;
  Fl_Value_Output *nInput;
  Fl_Counter *nOutput;
private:
  void cb_nOutput_i(Fl_Counter*, void*);
  static void cb_nOutput(Fl_Counter*, void*);
public:
  Fl_Button *Wbt;
private:
  void cb_Wbt_i(Fl_Button*, void*);
  static void cb_Wbt(Fl_Button*, void*);
public:
  Fl_Value_Slider *rTrain;
private:
  void cb_rTrain_i(Fl_Value_Slider*, void*);
  static void cb_rTrain(Fl_Value_Slider*, void*);
public:
  Fl_Value_Slider *rTest;
private:
  void cb_rTest_i(Fl_Value_Slider*, void*);
  static void cb_rTest(Fl_Value_Slider*, void*);
public:
  Fl_Check_Button *shuffle;
  Fl_Input *fName;
  Fl_Check_Button *Scale_D;
  Fl_Counter *Item;
private:
  void cb_Item_i(Fl_Counter*, void*);
  static void cb_Item(Fl_Counter*, void*);
public:
  Fl_Chart *Chart;
  Fl_Value_Slider *MinV;
private:
  void cb_MinV_i(Fl_Value_Slider*, void*);
  static void cb_MinV(Fl_Value_Slider*, void*);
public:
  Fl_Value_Slider *MaxV;
private:
  void cb_MaxV_i(Fl_Value_Slider*, void*);
  static void cb_MaxV(Fl_Value_Slider*, void*);
public:
  Fl_Check_Button *Scale_I;
private:
  void cb_Scale_I_i(Fl_Check_Button*, void*);
  static void cb_Scale_I(Fl_Check_Button*, void*);
public:
  Fl_Value_Input *Min;
private:
  void cb_Min_i(Fl_Value_Input*, void*);
  static void cb_Min(Fl_Value_Input*, void*);
public:
  Fl_Value_Input *Max;
private:
  void cb_Max_i(Fl_Value_Input*, void*);
  static void cb_Max(Fl_Value_Input*, void*);
public:
  void show();
  void hide();
  void GetItemData();
};
#include <FL/Fl_Light_Button.H>

class TDPDlg {
public:
  TDPDlg(char * FileName);
  Fl_Double_Window *window;
  Fl_Return_Button *Ok;
private:
  void cb_Ok1_i(Fl_Return_Button*, void*);
  static void cb_Ok1(Fl_Return_Button*, void*);
public:
  Fl_Output *RawFile;
  Fl_Value_Output *nDataPoint;
  Fl_Counter *nInput;
private:
  void cb_nInput_i(Fl_Counter*, void*);
  static void cb_nInput(Fl_Counter*, void*);
public:
  Fl_Button *Wbt;
private:
  void cb_Wbt1_i(Fl_Button*, void*);
  static void cb_Wbt1(Fl_Button*, void*);
public:
  Fl_Value_Slider *rTrain;
private:
  void cb_rTrain1_i(Fl_Value_Slider*, void*);
  static void cb_rTrain1(Fl_Value_Slider*, void*);
public:
  Fl_Value_Slider *rTest;
private:
  void cb_rTest1_i(Fl_Value_Slider*, void*);
  static void cb_rTest1(Fl_Value_Slider*, void*);
public:
  Fl_Check_Button *Shuffle;
private:
  void cb_Shuffle_i(Fl_Check_Button*, void*);
  static void cb_Shuffle(Fl_Check_Button*, void*);
public:
  Fl_Input *fName;
  Fl_Check_Button *Scale_D;
private:
  void cb_Scale_D_i(Fl_Check_Button*, void*);
  static void cb_Scale_D(Fl_Check_Button*, void*);
public:
  Fl_Group *Gr;
  Fl_Value_Input *Min;
private:
  void cb_Min1_i(Fl_Value_Input*, void*);
  static void cb_Min1(Fl_Value_Input*, void*);
public:
  Fl_Value_Input *Max;
private:
  void cb_Max1_i(Fl_Value_Input*, void*);
  static void cb_Max1(Fl_Value_Input*, void*);
public:
  Fl_Chart *Chart;
  Fl_Value_Slider *MinV;
private:
  void cb_MinV1_i(Fl_Value_Slider*, void*);
  static void cb_MinV1(Fl_Value_Slider*, void*);
public:
  Fl_Value_Slider *MaxV;
private:
  void cb_MaxV1_i(Fl_Value_Slider*, void*);
  static void cb_MaxV1(Fl_Value_Slider*, void*);
public:
  Fl_Light_Button *Hist;
private:
  void cb_Hist_i(Fl_Light_Button*, void*);
  static void cb_Hist(Fl_Light_Button*, void*);
  void cb_Time_i(Fl_Light_Button*, void*);
  static void cb_Time(Fl_Light_Button*, void*);
public:
  void show();
  void hide();
  void DrawGraph();
};
const char * OpenLink(Fl_Widget *w, const char *uri);
void Exit_CB(Fl_Widget*o, void*w);
#endif
